package com.str.graphs;
public class TraversalTest {

  private static final int NUM = 6; // Number of vertices
  private static final boolean UNDIRECTED = true;
  
  // Create a graph from array
  public static Graph createGraph(int[][] examp) {
    Graph g = new MatrixGraph(NUM);
   // Graph g = new ListGraph(NUM);

    for (int i=0; i<examp.length; i++) {
      int v1 = examp[i][0];
      int v2 = examp[i][1];
      int dist = 1;  // No weight given -- set at 1       
      if (examp[i].length > 2)
        dist = examp[i][2];
      g.setEdge(v1, v2, dist);
      if (UNDIRECTED) // Also put in edge in other direction
        g.setEdge(v2, v1, dist);
    }
    return g;
  }

  public static void print(Graph g) {
    System.out.println("Number of vertices is " + g.n());
    System.out.println("Number of edges is " + g.e());

    System.out.println("Matrix is:");
    for (int i=0; i<g.n(); i++) {
      for (int j=0; j<g.n(); j++)
        System.out.print(g.weight(i, j) + "  ");
      System.out.println();
    }
    System.out.println();
  }

  // Generic main function for graph tests --
  //   both adjacency list and adjacency graph
  public static void main(String args[]) {
  	
    int[][] examp = {{0, 1},        // (A, B)
                     {0, 4},        // (A, E)
                     {1, 2},        // (B, C)             
                     {1, 3},        // (B, D)
                     {1, 5},        // (B, F)
                     {2, 5},        // (C, F)
                     {3, 5},        // (D, F)
                     {4, 5}};  	    // (E, F)
    Graph g = createGraph(examp);
    print(g);
    Traversal.dfs(g);
    System.out.println();
    Traversal.bfs(g);
  }
}
